home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3463 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  50 lines

  1. Path: news.cyberhighway.net!usenet
  2. From: mjellis@cyberhighway.net
  3. Newsgroups: comp.lang.c
  4. Subject: Re: command line argument help
  5. Date: 29 Jan 1996 14:07:40 GMT
  6. Organization: Idaho Central Intechange
  7. Message-ID: <4eikbc$cs9@host-3.cyberhighway.net>
  8. References: <4edfth$ok@muss.CIS.McMaster.CA> <4egi4nINNncr@keats.ugrad.cs.ubc.ca>
  9. Reply-To: mjellis@cyberhighway.net
  10. NNTP-Posting-Host: rpm1-28.cyberhighway.net
  11. X-Newsreader: IBM NewsReader/2 v1.2.5
  12.  
  13. In <4egi4nINNncr@keats.ugrad.cs.ubc.ca>, c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  14. >In article <4edfth$ok@muss.CIS.McMaster.CA>,  <shadowfax> wrote:
  15. > >to all the c gods out there:
  16. > >
  17. > >i am not having too much success with command line arguments.  i am 
  18. > >trying to make a simple sumation executable for dos.  i am using borland 
  19. > >c++ v3.1.  what i want as the end result is the user just types:
  20. > >
  21. > >c:\> sum 6 3
  22. >
  23. >Get a decent shell that can do arithmetic.
  24. >
  25. >    echo $((6 + 3))
  26. >-- 
  27. >
  28.  
  29. Use something like the following:
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33.  
  34. void main(int argc, char *argv[])
  35. {
  36.    double a;   /*  First Operand  */
  37.    double b;   /*  Second Operand */
  38.    a = strtod(argv[1],NULL);   /*  Converts a string to a float a */
  39.    b = strtod(argv[2],NULL);   /*  Converts a string to a float b */
  40.    printf("%f",(a + b));
  41. }
  42.  
  43. I'll leave the error checking up to you.
  44.  
  45. John Ellis                                   
  46. mjellis@cyberhighway.net                     
  47. john@ici.usa.net                             
  48. Idaho Central Interchange BBS: (208) 677-2028
  49.  
  50.